﻿using System;
using System.Collections.Generic;
using System.Web;


namespace DBA.Common
{
    public class RequestHelper
    {
        public static List<HttpPostedFile> File()
        {
            List<HttpPostedFile> list = new List<HttpPostedFile>();
            foreach (HttpPostedFile file in HttpContext.Current.Request.Files)
            {
                list.Add(file);
            }
            return list;
        }

        public static HttpPostedFile File(string key)
        {
            return HttpContext.Current.Request.Files[key];
        }

        public static T Form<T>()
        {
            return ReflectorHelper.GetObject<T>(ReflectorHelper.GetKeyValueListFromForms());
        }

        public static string Form(string key)
        {
            try
            {
                return HttpContext.Current.Request.Form[key].ToString();
            }
            catch
            {
                return "";
            }
        }

        public static bool FormBoolean(string key)
        {
            return ConvertHelper.ToBoolean(Form(key));
        }

        public static byte FormByte(string key)
        {
            return ConvertHelper.ToByte(Form(key));
        }

        public static DateTime FormDateTime(string key)
        {
            return ConvertHelper.ToDateTime(Form(key));
        }

        public static decimal FormDecimal(string key)
        {
            return ConvertHelper.ToDecimal(Form(key));
        }

        public static string FormFilterString(string key)
        {
            return HtmlHelper.NoHTML(Form(key));
        }

        public static Guid FormGuid(string key)
        {
            return ConvertHelper.ToGuid(Form(key));
        }

        public static short FormInt16(string key)
        {
            return ConvertHelper.ToInt16(Form(key));
        }

        public static int FormInt32(string key)
        {
            return ConvertHelper.ToInt32(Form(key));
        }

        public static long FormInt64(string key)
        {
            return ConvertHelper.ToInt64(Form(key));
        }

        public static bool FormIsNull(string key)
        {
            return VerificationHelper.IsNullOrEmpty(Form(key));
        }

        public static bool IsPostBack()
        {
            return (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST");
        }

        public static string QueryString(string key)
        {
            try
            {
                return HttpContext.Current.Request.QueryString[key].ToString();
            }
            catch
            {
                return string.Empty;
            }
        }

        public static bool QueryStringBoolean(string key)
        {
            return ConvertHelper.ToBoolean(QueryString(key));
        }

        public static byte QueryStringByte(string key)
        {
            return ConvertHelper.ToByte(QueryString(key));
        }

        public static DateTime QueryStringDateTime(string key)
        {
            return ConvertHelper.ToDateTime(QueryString(key));
        }

        public static decimal QueryStringDecimal(string key)
        {
            return ConvertHelper.ToDecimal(QueryString(key));
        }

        public static Guid QueryStringGuid(string key)
        {
            return ConvertHelper.ToGuid(QueryString(key));
        }

        public static short QueryStringInt16(string key)
        {
            return ConvertHelper.ToInt16(QueryString(key));
        }

        public static int QueryStringInt32(string key)
        {
            return ConvertHelper.ToInt32(QueryString(key));
        }

        public static long QueryStringInt64(string key)
        {
            return ConvertHelper.ToInt64(QueryString(key));
        }

        public static bool QueryStringIsNull(string key)
        {
            return VerificationHelper.IsNullOrEmpty(QueryString(key));
        }

    }
}
